#include <stdio.h>
#include "main.h"
#include "lmexxx_conf.h"
#include "MseProcess.h"
#include "controller.h"
#include "panel.h"
#include "key.h"
#include "output.h"

extern void CmdTest_MSE_Load_Product(void);

int main(void)
{
	nvic_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);
	systimer_init();
	// debug_uart_init();
	i2c_init();
	buzzer_init();
	button_init();
	// irm_init();
	comm_uart_init();
	ntc_init();
	relay_init();
	led_init();
	panel_init();
	controller_init();
	CmdTest_MSE_Load_Product();
	
// extern void eeprom_test(void);
//	char str[] = "Hello GD32\n";
//	comm_send_bytes(str, sizeof(str));
//	printf("Hello GD32(pirntf)\r\n");
	
	while(1)
	{
		if(systemTimer.flag5ms)
		{
			systemTimer.flag5ms = 0;
			button_scan();
		}
		if(systemTimer.flag10ms)
		{
			systemTimer.flag10ms = 0;
		}
		if(systemTimer.flag20ms)
		{
			systemTimer.flag20ms = 0;
		}
		if(systemTimer.flag50ms)
		{
			systemTimer.flag50ms = 0;
		}
		if(systemTimer.flag100ms)
		{
			systemTimer.flag100ms = 0;
			panel_process();
		}
		if(systemTimer.flag200ms)
		{
			systemTimer.flag200ms = 0;
			sensor_process();
            button_process();
		}
		if(systemTimer.flag500ms)
		{
			systemTimer.flag500ms = 0;
			output_process();
		}
		if(systemTimer.flag1000ms)
		{
			systemTimer.flag1000ms = 0;
			low_power_process();
            sys_params_save();
			comm_sender_process();
		}
		comm_receiver_process();
	}
}


